<?php
 
/*

***************************************
*                                     *
* Copyright 2011 David Matthew Pugh   *
* Contact Info:thebravedave@gmail.com *
*                                     *
***************************************

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
                          
// Include the sidebar file:
$page_title = 'Shopping Cart'; 
include ('./includes/sidebar.php');

echo '<h1>View Your Shopping Cart<img src="http://yourwebdevcenter.com/projects/ecommerce_merchant_exchange_package/images/empty_shopping_cart.jpg"></a></h1>';

// Create the shopping cart:
require_once('WidgetShoppingCart.php');
if (isset($_SESSION['cart'])) 
{
	$cart = unserialize($_SESSION['cart']);
     
} 
else 

{
	print "No Items in Shopping Cart";
    $cart = new WidgetShoppingCart();
}
  
           
     


if (isset($_REQUEST['do']) && ($_REQUEST['do'] == 'update')) 
{

	// Change any quantities...
	// $k is the product ID.
	// $v is the new quantity.
	foreach ($_POST['qty'] as $k => $v) 
    {
	
		// Must be integers!
		$pid = (string) $k;
		$qty = (int) $v;
       
       
       
		$cart->update_item($pid, $qty);
    
	} // End of FOREACH.
    $cart->add_identifier();
    
	echo '    
        <script type="text/javascript">
        <!--
        window.location = "./cart.php?page_title=Cart Contents"
        //-->
        </script> 
        ';

	
	

	
//End of if(Request[do] and do=update     }
}               
// Show the shopping cart if it's not empty:
if (!$cart->is_empty()) 
{
	$cart->display_cart('cart.php');
} 
else 
{
	echo '<p>Your cart is currently empty.</p>';
}

// Store the cart in the session:
$_SESSION['cart'] = serialize($cart);


include_once ('./includes/footer.html');

 ?>
 </form>



